{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('../data/gapminder.tsv', sep='\\t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>country</th>\n",
       "      <th>continent</th>\n",
       "      <th>year</th>\n",
       "      <th>lifeExp</th>\n",
       "      <th>pop</th>\n",
       "      <th>gdpPercap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1952</td>\n",
       "      <td>28.801</td>\n",
       "      <td>8425333</td>\n",
       "      <td>779.445314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1957</td>\n",
       "      <td>30.332</td>\n",
       "      <td>9240934</td>\n",
       "      <td>820.853030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1962</td>\n",
       "      <td>31.997</td>\n",
       "      <td>10267083</td>\n",
       "      <td>853.100710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1967</td>\n",
       "      <td>34.020</td>\n",
       "      <td>11537966</td>\n",
       "      <td>836.197138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>Asia</td>\n",
       "      <td>1972</td>\n",
       "      <td>36.088</td>\n",
       "      <td>13079460</td>\n",
       "      <td>739.981106</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       country continent  year  lifeExp       pop   gdpPercap\n",
       "0  Afghanistan      Asia  1952   28.801   8425333  779.445314\n",
       "1  Afghanistan      Asia  1957   30.332   9240934  820.853030\n",
       "2  Afghanistan      Asia  1962   31.997  10267083  853.100710\n",
       "3  Afghanistan      Asia  1967   34.020  11537966  836.197138\n",
       "4  Afghanistan      Asia  1972   36.088  13079460  739.981106"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "year\n",
       "1952    49.057620\n",
       "1957    51.507401\n",
       "1962    53.609249\n",
       "1967    55.678290\n",
       "1972    57.647386\n",
       "1977    59.570157\n",
       "1982    61.533197\n",
       "1987    63.212613\n",
       "1992    64.160338\n",
       "1997    65.014676\n",
       "2002    65.694923\n",
       "2007    67.007423\n",
       "Name: lifeExp, dtype: float64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('year')['lifeExp'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "year  continent\n",
       "1952  Africa       39.135500\n",
       "      Americas     53.279840\n",
       "      Asia         46.314394\n",
       "      Europe       64.408500\n",
       "      Oceania      69.255000\n",
       "1957  Africa       41.266346\n",
       "      Americas     55.960280\n",
       "      Asia         49.318544\n",
       "      Europe       66.703067\n",
       "      Oceania      70.295000\n",
       "1962  Africa       43.319442\n",
       "      Americas     58.398760\n",
       "      Asia         51.563223\n",
       "      Europe       68.539233\n",
       "      Oceania      71.085000\n",
       "1967  Africa       45.334538\n",
       "      Americas     60.410920\n",
       "      Asia         54.663640\n",
       "      Europe       69.737600\n",
       "      Oceania      71.310000\n",
       "1972  Africa       47.450942\n",
       "      Americas     62.394920\n",
       "      Asia         57.319269\n",
       "      Europe       70.775033\n",
       "      Oceania      71.910000\n",
       "1977  Africa       49.580423\n",
       "      Americas     64.391560\n",
       "      Asia         59.610556\n",
       "      Europe       71.937767\n",
       "      Oceania      72.855000\n",
       "1982  Africa       51.592865\n",
       "      Americas     66.228840\n",
       "      Asia         62.617939\n",
       "      Europe       72.806400\n",
       "      Oceania      74.290000\n",
       "1987  Africa       53.344788\n",
       "      Americas     68.090720\n",
       "      Asia         64.851182\n",
       "      Europe       73.642167\n",
       "      Oceania      75.320000\n",
       "1992  Africa       53.629577\n",
       "      Americas     69.568360\n",
       "      Asia         66.537212\n",
       "      Europe       74.440100\n",
       "      Oceania      76.945000\n",
       "1997  Africa       53.598269\n",
       "      Americas     71.150480\n",
       "      Asia         68.020515\n",
       "      Europe       75.505167\n",
       "      Oceania      78.190000\n",
       "2002  Africa       53.325231\n",
       "      Americas     72.422040\n",
       "      Asia         69.233879\n",
       "      Europe       76.700600\n",
       "      Oceania      79.740000\n",
       "2007  Africa       54.806038\n",
       "      Americas     73.608120\n",
       "      Asia         70.728485\n",
       "      Europe       77.648600\n",
       "      Oceania      80.719500\n",
       "Name: lifeExp, dtype: float64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['year', 'continent'])['lifeExp'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
